package com.news.common;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Author:weiming
 * @Date:2021/3/24
 */
public class BaseServlet extends HttpServlet {


    @Override
    public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

        String methodName = req.getParameter("method");
            if (methodName != null || !"".equals(methodName)) {
                try {
                    Method method = this.getClass().getMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
                    System.out.println(method.toString());
                    method.invoke(this, req, res);
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
    }
}
